package cn.dianhun.om.jpa.controller;

import cn.dianhun.om.jpa.pojo.SysRoleMenuEntity;
import cn.dianhun.om.jpa.repository.RoleMenuReposity;
import cn.dianhun.om.jpa.utills.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cyt
 * @create 2020-07-08 15:16
 */

@RestController
public class testRoleMenuController {

    @Autowired
    private RoleMenuReposity roleMenuReposity;


    @PostMapping("/query")
    public R query(@RequestBody SysRoleMenuEntity roleMenuEntity) {

        ExampleMatcher matcher = ExampleMatcher.matching()
                .withStringMatcher(ExampleMatcher.StringMatcher.CONTAINING)
                //改变默认字符串匹配方式：模糊查询
                .withIgnoreCase(true)
                //改变默认大小写忽略方式：忽略大小写
                .withIgnoreCase("long")
                // .withMatcher("roleId", ExampleMatcher.GenericPropertyMatchers.startsWith())
                .withMatcher("menuId", ExampleMatcher.GenericPropertyMatchers.startsWith());
        //地址采用“开始匹配”的方式查询

        //创建实例
        Example<SysRoleMenuEntity> ex = Example.of(roleMenuEntity, matcher);

        //查询
        List<SysRoleMenuEntity> userEntities = roleMenuReposity.findAll(ex);

        return R.ok().data("info", userEntities);
    }
}
